Skip to content

Offload tool call persistence to executor for faster SSE#64

Merged
trialiya merged 1 commit into
mainfrom
claude/toolcalls-save-async-5a7m15
Jun 26, 2026
Merged

Offload tool call persistence to executor for faster SSE#64
trialiya merged 1 commit into
mainfrom
claude/toolcalls-save-async-5a7m15

Conversation

@trialiya

@trialiya trialiya commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

Defer database persistence of tool call state to a background executor to prevent blocking Server-Sent Events (SSE) on disk I/O.

Changes

  • Wrapped chatMemoryService.saveToolCallIncremental() call in executor.execute() to run asynchronously
  • Extracted tcm.toolCall() to a local variable to ensure consistent reference in the async closure
  • Added clarifying comment explaining the rationale: DB writes are best-effort bookkeeping that should not delay SSE delivery to clients

Implementation Details

The tool call persistence is now treated as non-blocking bookkeeping. When a tool invocation completes (status != STARTED), the state is saved to the database in the background while the SSE event is published immediately. This improves perceived responsiveness of the chat interface without sacrificing durability, since the tool call data is still persisted—just not synchronously.

SSE event was blocked on disk I/O before reaching the client.
Submitting the INSERT to the existing virtual-thread executor lets
events.publish() run immediately after the tool finishes, while the
write happens concurrently. The batch save in onComplete writes to a
separate table (chat_message), so there is no ordering dependency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185eo9C1XmDGioNAvUPweNv
@trialiya trialiya merged commit 34f538f into main Jun 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants